import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringExtractor {

    public static void main(String[] args) {
         System.out.println("Hello world!");
    }

    public static void extractStrings(String filePath) {
        // 正则表达式匹配双引号内的字符串
        String regex = "\"(\\\\.|[^\"])*\"";
        Pattern pattern = Pattern.compile(regex);

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                Matcher matcher = pattern.matcher(line);
                while (matcher.find()) {
                    String str = matcher.group();
                    // 去除字符串的双引号，并处理转义字符
                    String unescapedStr = unescapeJavaString(str.substring(1, str.length() - 1));
                    System.out.println(unescapedStr);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 处理转义字符的函数
    public static String unescapeJavaString(String str) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch == '\\' && i < str.length() - 1) {
                char nextChar = str.charAt(i + 1);
                switch (nextChar) {
                    case '"': result.append('"'); i++; break;
                    case '\\': result.append('\\'); i++; break;
                    case 'n': result.append('\n'); i++; break;
                    case 't': result.append('\t'); i++; break;
                    default: result.append(ch); break;
                }
            } else {
                result.append(ch);
            }
        }
        return result.toString();
    }
}
